an integrated development environment specifically for python - developed by the Czech company JetBrains - the community edition provides an intelligent editor, graphical debugger, refactorings, code inspections and version control integration



install

brew cask install pycharm-ce

projects

make a new project

set the interpreter


prefrences

shortcuts

Description Shortcut
Preferences CMD + ,
Jump to definition CMD + B
Popup of recent files CMD + E
Parameter info CMD + P
Find action CMD + SHIFT + A
Code completion CTRL + SPACE
Move between methods CTRL + UP/DOWN
F1 View documentation popup

Personal setup - modified using Preferences > Keymap:

Description Shortcut Keymap location
Execute in python console CMD + ENTER Plug-Ins/Python Community Edition/Execute Selection In Python Console
Comment/uncomment SHIFT + CMD + C Main menu/Code/Comment with Line Comment
Auto-indent CMD + I Main menu/Code/Auto-Indent Lines
Toggle soft-wrap SHIFT + CMD + W Main menu/View/Active Editor/Soft-Wrap
Run SHIFT + CMD + S Main menu/Run/Run
Debug SHIFT + CMD + D Main menu/Run/Debug

other

what where
Custom font Preferences > Appearance & Behaviour > Appearance
Default project directory Preferences > Appearance & Behaviour > System Settings
Don’t open previous projects Preferences > Appearance & Behaviour > System Settings > Reopen last project on startup
Soft wrap Preferences > General > Console
Custom font Preferences > Editor > Font
Vertical guidelines Preferences > Editor > Code Style > General > Visual guides: 72,79 columns
Templates Preferences > Editor > File and Code Templates
Plugins Preferences > Plugins
Default interpreter Preferences > Project > Project Interpreter
IPython console Preferences > Build, Execution, Deployment > Console > Use IPython if available
Docstring format Preferences > Tools > Python Integrated Tools > Docstrings > File and Code Templates

window layout

My personal setup:

What Move to
Python Console Bottom Top
Terminal Bottom Right
Todo Bottom Right
Run Bottom Right

Window > Use current layout as default


console

Use IPython if available (i.e. installed in your python env)

  • Go to Preferences > Build, Execution, Deployment > Console
  • then check Use IPython if available

code style

Add visual guidelines:

  • 72 (docstrings/comments)
  • 79 (code)

See https://pep8.org/#maximum-line-length

Preferences > Editor > Code Style > General > Visual guides: 72,79 columns

plugins

Preferences > Plugins

  • Markdown

default interpreter

File > Other settings > Project Interpreter

run configurations


todo

make a new py file

within the project, right click on the project folder wand then click New > Python file

set the interpreter

  • set the project interpreter

  • this will be the interpreter used in the pycharm python console

  • e.g. to set the interpreter to an existing conda env

  • PyCharm >

  • Preferences >

  • Project: [my project] >

  • Project Interpreter >

  • Project Interpreter... >

  • [Settings wheel] >

  • Add... >

  • Conda Environment >

  • Existing Environment >

  • Interpreter

  • then choose make available to all projects (if you want it to be)

  • Dont forget to Apply before clicking Ok

things to note:

  • if you change the project interpreter you may need to close and re-launch the python console for the change to take effect:
    • close the console, then click Tools > Pycharm console...

run script

Run > Run >

then either:

  • select file from drop down to use existing interpreter etc, or
  • edit configurations to change interpreter and/or command args etc.

things to note:

  • when you run a script it gets run in a new terminal tab called Run
  • this is not the same thing as the pycharm python console
  • you can change the interpreter used in the run terminal from the edit configurations window
  • changing this will not change the interpreter used in the pycharm python console, although it’s probably a good idea to use the same interpreter for both

switching project

File > Open Recent


customisation

shortcuts

  • PyCharm >
  • Preferences >
  • Appearances & Behaviour >
  • Keymap

misc

shortcut action
CTRL R run script from terminal
CTRL SPACE help with code completion
CTRL UP/DOWN move between methods in editor
CTRL + OPTION + I auto indent selection
CMD / auto comment/uncomment lines
CMD , open preferences
CMD B jump to function definition
CMD E opens a popup of recently visited files
CMD P view parameter info
CMD SHIFT A open ‘Find Action’ utility
SHIFT OPTION E run line / selection in python console

code folding

shortcut action
CMD + expand section
CMD - collapse section
SHIFT CMD + expand all sections
SHIFT CMD - collapse all sections

git integration